Skip to content

Do not classify recursive self-reference ref cells as mutable#19918

Open
T-Gro wants to merge 3 commits into
mainfrom
fix/issue-5229
Open

Do not classify recursive self-reference ref cells as mutable#19918
T-Gro wants to merge 3 commits into
mainfrom
fix/issue-5229

Conversation

@T-Gro

@T-Gro T-Gro commented Jun 9, 2026

Copy link
Copy Markdown
Member

Fixes #5229

SemanticClassification.isValRefMutable treated compiler-generated ref
cells for recursive self-references (as this, let rec self-refs) as
user-written mutable bindings, causing wrong IDE colorization.

Copilot and others added 3 commits June 9, 2026 08:29
…bleVar)

Adds positive and negative coverage for SemanticClassification of `as this` self-references in class bodies. These tests currently fail because isValRefMutable in SemanticClassification.fs treats the internal ref-cell compilation of CtorThisVal as a user-written mutable binding. Sprint 02 applies the surgical fix to make them pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The compiler compiles recursive object self-references (`as this`,
recursive `let rec` self-refs) through a ref cell for initialization.
SemanticClassification.isValRefMutable previously treated that internal
ref cell as a user-written mutable binding, causing the IDE colorizer
to paint the self-reference with the MutableVar shade.

Mirror the existing guard in FSharpMemberOrFunctionOrValue.IsMutable
(src/Compiler/Symbols/Symbols.fs) by excluding vref.IsCtorThisVal from
the isRefCellTy branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply dotnet fantomas to the SemanticClassification fix and its regression tests (both already conformant, no diff); add a release-notes entry for the service-side change. No production logic changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

❗ Release notes required

You can open this PR in browser to add release notes: open in github.dev


✅ Found changes and release notes in following paths:

Warning

No PR link found in some release notes, please consider adding it.

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.100.md No current pull request URL (#19918) found, please consider adding it

@github-actions github-actions Bot added the AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed label Jun 9, 2026
@T-Gro T-Gro requested a review from abonie June 12, 2026 10:08

@T-Gro T-Gro left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix. The one-line guard (not vref.IsCtorThisVal) mirrors the existing parallel logic in Symbols.fs line 2376 (IsRefCell), so both the public API and semantic classification now agree on what constitutes a mutable binding.

Tests cover the positive case (as this not marked mutable), theory variants, and negative guards (real mutable/ref-cell/byref/record-field bindings still classified correctly). Release notes entry is accurate.

LGTM — ship it.

@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-reviewed PR reviewed by AI review council AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

Recursive object reference colored as a mutable variable

1 participant